package com.cyzy.service.impl;

import com.cyzy.config.WeatherConfig;
import com.cyzy.service.WeatherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * 天气服务实现类
 */
@Service
public class WeatherServiceImpl implements WeatherService {
    
    @Autowired
    private WeatherConfig weatherConfig;
    
    @Autowired
    private RestTemplate restTemplate;
    
    @Override
    public String getWeatherInfo() {
        try {
            // 构建完整的API URL
            String url = weatherConfig.getUrl() + 
                        "?appid=" + weatherConfig.getAppid() +
                        "&appsecret=" + weatherConfig.getAppsecret();
            
            // 调用外部API
            String response = restTemplate.getForObject(url, String.class);
            
            return response;
        } catch (Exception e) {
            throw new RuntimeException("获取天气信息失败：" + e.getMessage());
        }
    }
} 